<?php 
namespace Ng\Model;
use Think\Model;
class QuestionModel extends Model {
  public function getlist($where='',$currentPage=1,$pageSize=10){
    $model = M('question');

    $obj = $model
    ->alias('q')
    ->field('t.type_name,u.id as uid,q.id as qid,u.user_name,u.user_image,q.question_title,q.question_time,q.question_view,q.question_comment,q.question_type,q.question_status,s.status_name')
    ->join('think_user as u ON q.question_uid = u.id', 'left')
    ->join('think_question_type as t ON q.question_type = t.id', 'left')
    ->join('think_question_status as s on q.question_status = s.status', 'left')
    ->where($where)
    ->order('q.question_time desc')
    ->page($currentPage?$currentPage:1,$pageSize?$pageSize:10)
    ->select();

    $total = $model
    ->alias('q')
    ->join('think_user ON q.question_uid = think_user.id', 'left')
    ->join('think_question_type as t ON q.question_type = t.id', 'left')
    ->join('think_question_status as s on q.question_status = s.status', 'left')
    ->where($where)
    ->count();

    $data->obj = $obj;
    $data->total = $total;
    return $data;
  }

  public function getUserPublishList($page){
    $model = M('user');

    $obj = $model
    ->alias('u')
    ->field('u.id as uid,a.id as aid,u.user_name,u.id as uid,u.user_image,count(a.id) AS answer_conut')
    ->join('think_answer AS a ON u.id = a.answe_uid', 'left')
    ->order('answer_conut desc')
    ->group('u.id')
    ->page(1,$page)
    ->select();

    $data->obj = $obj;
    return $data;
  }

  public function getQuestionWatchList($page){
    $model = M('question');
    $obj = $model
    ->alias('q')
    ->field('q.question_title,q.id as qid,q.question_view')
    ->order('q.question_view desc')
    ->page(1,$page)
    ->select();

    $data->obj = $obj;
    return $data;
  }

  public function getQuestionPublishList($page){
    $model = M('question');
    $obj = $model
    ->alias('q')
    ->field('q.id as qid,q.question_title,count(a.id) AS answer_conut')
    ->join('think_answer AS a ON q.id = a.answer_qid','left')
    ->order('answer_conut desc')
    ->group('q.id')
    ->page(1,$page)
    ->select();

    $data->obj = $obj;
    return $data;
  }
}
?>